<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller
{
    public function index()
    {
        $pd = "用户管理";
        $pt = "用户列表";
        $this->assign('pd', $pd);
        $this->assign('pt', $pt);
        $sql = "select * from user";
        $m = M();
        $user = $m->query($sql);
        $this->assign('user', $user);
        $this->display("index");
//        echo "dsdsssd";
    }

    public function group_list()
    {
        $pd = "用户管理";
        $pt = "用户组";
        $this->assign('pd', $pd);
        $this->assign('pt', $pt);
        $this->display("group_list");
    }

    public function job_list()
    {
        $m = M();
        $sql = "select * from zhiwei";
        $ret = $m->query($sql);
        $pd = "用户管理";
        $pt = "职位设置";
        $this->assign('pd', $pd);
        $this->assign('pt', $pt);
        $this->assign('ret', $ret);
        $this->display("job_list");
        if (IS_POST) {
            $text = I("post.text");
            $arry = explode("\n", $text);
            $ntext = array();
            foreach ($arry as $v) {
                $ne = str_replace(' ', "", $v);
                $ntext[] = $ne;
            }
            $m = M();
            $ret = 0;

            foreach ($ntext as $v) {

                if ($this->qvchong($v)==1){
                    $sql = "insert into zhiwei(zhiweiname) VALUES ('{$v}')";
                    $ret += $m->execute($sql);
                }
            }
        }
    }
    private function qvchong($v)
    {
        $m = M();
        $sql = "select * from zhiwei";
        $arr = $m->query($sql);
        foreach ($arr as $vl) {
            if ($vl['text'] == $v) {
                return 0;
            }
        }
        return 1;
    }
    public function manage(){
        $id = I("post.id");
        $m = M();
        $sql = "delete from zhiwei where id = {$id}";
        if($m->execute($sql)!=0){
            echo "<script type='text/javascript'>window.parent.location.href=''</script>";
        }else{

        };
    }
     public function user_edit(){
         if(IS_GET){
                 $arr = array(
                     "请选择省份或直辖市",
                     "安徽省",
                     "北京市",
                     "福建省",
                     "甘肃省",
                     "广东省",
                     "广西壮族自治区",
                     "贵州省",
                     "海南省",
                     "河北省",
                     "河南省",
                     "黑龙江省",
                     "湖北省",
                     "湖南省",
                     "吉林省",
                     "江苏省",
                     "江西省",
                     "辽宁省",
                     "内蒙古自治区",
                     "宁夏回族自治区",
                     "青海省",
                     "山东省",
                     "山西省",
                     "陕西省",
                     "上海市",
                     "四川省",
                     "天津市",
                     "西藏自治区",
                     "新疆维吾尔自治区",
                     "云南省",
                     "浙江省",
                     "重庆市",
                     "香港",
                     "澳门",
                     "台湾"
                 );
                 $id = I("get.id");
                 $m = M();
                 $sql = "select * from user where id = {$id}";
                 $ret = $m->query($sql);
                 $ret = $ret[0];
                 $sql = "select * from zhiwei";
                 $rtt = $ett = $m->query($sql);
                 $this->assign('rtt', $rtt);
                 $this->assign('ret', $ret);
                 $this->assign('id', $id);
                 $this->assign('arr', $arr);
                 $this->display("user_edit");
             }
         if(IS_POST){
             $user_name= I("post.user_name");
             $mail = I("post.mail");
             $user_press = I("post.password");
             $dz_sf = I("post.dz_sf");
             $dh = I("post.dh");
             $qq = I("post.qq");
             $cymail = I("post.cymail");
             $wz =I("post.wz");
             $js = I("post.js");
             $id =I("post.uid");
             $m =M();
             if($user_press==""){
                 $sql = "update user set user_name='{$user_name}',mail='{$mail}',dz_sf='{$dz_sf}',dh='{$dh}',qq='{$qq}',cymail='$cymail',wz='{$wz}',js='{$js}' where id = $id;";
             }else{
                 $sql = "update user set user_name='{$user_name}',mail='{$mail}',dz_sf='{$dz_sf}',dh='{$dh}',qq='{$qq}',cymail='$cymail',wz='{$wz}',js='{$js},user_press='$user_press' where id = $id;";
             }
             if($m->execute($sql)!=0){
                 $this->error("修改完成",U('Admin/user/index'));
             }else{
                 $this->error("修改失败",U(''));
             };
         }
         }
     public function baidu(){
         //第一个统计表
         $arr = array('categories'=>array(
                '衬衫',
                '毛衣',
                '呵呵',
                '哈哈',
         ),
             'data'=>array(
                 12,
                 13,
                 20,
                 21,
                 4,
             )

         );

         echo json_encode($arr);

     }
    public function dong(){

    }
}